package server.model.solver.maze;

import java.util.ArrayList;

import server.model.solver.maze.algorithms.*;

public class MazeDomain implements IDomain {
	private Maze maze;

	public MazeDomain(Maze maze) {
		this.maze = maze;
	}

	public ArrayList<IAction> getActions(State state) {
		MazeState mazeState = (MazeState)state;
		
		ArrayList<IAction> actions = new ArrayList<IAction>();

		for (int xIndex = -1; xIndex <= 1; xIndex++) {
			for (int yIndex = -1; yIndex <= 1; yIndex++) {
				if (xIndex != 0 || yIndex != 0) {
					int x = mazeState.getX() + xIndex;
					int y = mazeState.getY() + yIndex;
				
					int mazeValue = this.maze.get(x, y);
					
					if (mazeValue == Maze.EMPTY_INDICATOR || mazeValue == Maze.GOAL_INDICATOR) {
						actions.add(new MazeAction(xIndex, yIndex));
					}
				}
			}
		}

		return actions;
	}

	public double distance(State state, State goal) {
		IDistance g = new MazeG();
		return g.getDistance(state, goal);
	}

	public State getStartState() {
		return maze.getStartState();
	}

	public State getGoalState() {
		return maze.getGoalState();
	}
}
